#ifndef MINISHELLBASE_H
#define MINISHELLBASE_H

// ===== libraries =====
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#include <dirent.h>
#include <fcntl.h>
#include <errno.h>
#include <stdbool.h>
#include <sys/wait.h>

// ============ macro definition ============
// for welcom_cmd_text
#define LINE_LENGTH 40
#define LINE_NUMBER 10

// for property of prompt string
#define PROMPT_NUMBER 2
#define MAX_PAPA_NUM 10
#define MAX_ENV_VALUE_LENGTH 2048

#define TRUE 1
#define FALSE 0

#define MAX_PROMPT_LENGTH  2048  // Max character length of input from user
#define SELF_DEF_TYPE_NUM  10   // Max number of the self-defined prompt type
#define MATCHED 0
#define TRUE   1
#define FALSE  0
#define NULL_CHAR '\0'

// Error handler
// ASCII
#define SPACE (char) 32


// ============ key variable definition ============
/** @addtogroup prompt_type
 * @brief	Define the prompt type, which is a general characteristics of prompt cmd_text.
 */

// forward declaration
typedef struct PROMPT_TYPE PROMPT_TYPE;

typedef struct
{
	unsigned int index; // index of the prompt type within the structural array of selfDef_type
	PROMPT_TYPE* selfDef_type;
	char* cmd_string;
	char** parameters;
	size_t para_num;
}PARSER;

struct PROMPT_TYPE{
	size_t cmd_length;
	size_t max_para_num;
	char* cmd_text;
	PARSER * (*fcn_ptr)(PARSER *); // semantic understanding and command execution 
} ; // general characteristics of prompt cmd_text

// length of the function list
// const size_t fcnList_len = 2;

// === built-in commands ===
PARSER * _ECHO(PARSER * cmd);
PARSER * _CD(PARSER * cmd);

void Clear_space(char **str_prt, size_t count);
void Print_current_workpath();
int initialize();
void Print_errorInfo(const char * errorstr,const char * filename, const int linenum );
void load_fcnList(PROMPT_TYPE *selfDef_types);
void Semantic_Segmentation(char ** token, char ** inputstr, const char * seg_symbol, int iswarning);
int Identify_promptType(char* str, PROMPT_TYPE* array_selfDef_type, size_t array_len,PARSER *cmd);
void Clear_space(char **str_prt, size_t count);
void Free_parser(PARSER **cmd);
void Free_promptTypeList(PROMPT_TYPE ** array_selfDef_type, size_t array_len);
char * Input_string();
char* get_self_path();
void executeExternCMD(char *input_str, char * path2exe);

#endif